package leets.leet2344;

import java.util.Arrays;

public class Solution {
    public int minOperations(int[] nums, int[] numsDivide) {
        int divide=numsDivide[0];
        for (int i = 1; i < numsDivide.length; i++) {
            divide=getDivide(divide,numsDivide[i]);
        }
        Arrays.sort(nums);
        int res=-1;

        for (int i = 0; i < nums.length; i++) {
            if (nums[i]<=divide&&(divide%nums[i])==0){
                res=i;
                break;
            }
        }
        return res;
    }
    public int getDivide(int x,int y){
        if (x<y){
            int temp=y;
            y=x;
            x=temp;
        }
        while (y>0){
            int temp=x%y;
            x=y;
            y=temp;
        }
        return x;
    }
}